{% extends 'base.html.twig' %}
{% import 'Import/app_import.html.twig' as appImport %}

{% block head_title %}{{ 'elasticsearch_users'|trans }} - {{ user.name }}{% endblock %}

{% block heading_1 %}
    {{ appImport.heading({'level': 1, 'title': 'elasticsearch_users'|trans, 'link': {'url': path('elasticsearch_users')}}) }}
{% endblock %}

{% block heading_2 %}
    {{ appImport.heading({'level': 2, 'title': user.name}) }}
{% endblock %}

{% block tabs %}
    {% include 'Modules/user/user_read_tabs.html.twig' with {'active': 'summary'} %}
{% endblock %}

{% block main_content %}
    {% embed 'Embed/block_embed.html.twig' %}
        {% import 'Import/app_import.html.twig' as appImport %}
        {% block content %}
            {{ appImport.heading({'level': 3, 'title': 'summary'|trans}) }}

            {% embed 'Embed/buttons_embed.html.twig' %}
                {% import 'Import/app_import.html.twig' as appImport %}
                {% block content %}
                    {% if is_granted('ELASTICSEARCH_USER_DELETE', user) %}
                        {{ appImport.buttonModal({
                            'id': 'UserDelete',
                            'title': 'delete'|trans,
                            'body': user.name,
                            'href': path('elasticsearch_users_delete', {'user': user.name}),
                        }) }}
                    {% endif %}

                    {% if is_granted('ELASTICSEARCH_USER_ENABLE', user) %}
                        {{ appImport.buttonModal({
                            'id': 'UserEnable',
                            'title': 'enable'|trans,
                            'body': user.name,
                            'href': path('elasticsearch_users_enable', {'user': user.name}),
                        }) }}
                    {% endif %}

                    {% if is_granted('ELASTICSEARCH_USER_DISABLE', user) %}
                        {{ appImport.buttonModal({
                            'id': 'UserDisable',
                            'title': 'disable'|trans,
                            'body': user.name,
                            'href': path('elasticsearch_users_disable', {'user': user.name}),
                        }) }}
                    {% endif %}
                {% endblock %}
            {% endembed %}

            <div class="row">
                <div class="col-12 col-md-5 col-lg-4">
                    {% if user.fullName %}
                        <p>
                            <strong>{{ 'full_name'|trans }}</strong><br>
                            {{ user.fullName }}
                        </p>
                    {% endif %}

                    {% if user.email %}
                        <p>
                            <strong>{{ 'email'|trans }}</strong><br>
                            {{ user.email }}
                        </p>
                    {% endif %}

                    {% if user.roles and 0 < user.roles|length %}
                        <p>
                            <strong>{{ 'elasticsearch_roles'|trans }}</strong><br>
                            {% for record in user.roles %}
                                <a class="{{ theme_link_secondary }}" href="{{ path('elasticsearch_roles_read', {'role': record}) }}">{{ record }}</a>{% if false == loop.last %}, {% endif %}
                            {% endfor %}
                        </p>
                    {% endif %}

                    <p>
                        <strong>{{ 'enabled'|trans }}</strong><br>
                        {{ appImport.badge({'title': ('boolean.' ~ user.enabled)|trans, 'context': user.enabled}) }}
                    </p>

                    <p>
                        <strong>{{ 'reserved'|trans }}</strong><br>
                        {% if user.isReserved %}
                            {{ appImport.badge({'title': 'boolean.true'|trans, 'context': 'true'}) }}
                        {% else %}
                            {{ appImport.badge({'title': 'boolean.false'|trans, 'context': 'false'}) }}
                        {% endif %}
                    </p>

                    <p>
                        <strong>{{ 'deprecated'|trans }}</strong><br>
                        {% if user.isDeprecated %}
                            {{ appImport.badge({'title': 'boolean.true'|trans, 'context': 'true'}) }}
                        {% else %}
                            {{ appImport.badge({'title': 'boolean.false'|trans, 'context': 'false'}) }}
                        {% endif %}
                    </p>

                    {% if user.isDeprecated and user.deprecatedReason %}
                        <p>
                            <strong>{{ 'deprecated_reason'|trans }}</strong><br>
                            {{ user.deprecatedReason }}
                        </p>
                    {% endif %}
                </div>

                {% if user.metadata and 0 < user.metadata|length %}
                    <div class="col-12 col-md-5 col-lg-4">
                        <p>
                            <strong>{{ 'metadata'|trans }}</strong><br>
                            <pre>{{ user.metadata|json_encode(constant('JSON_PRETTY_PRINT')) }}</pre>
                        </p>
                    </div>
                {% endif %}
            </div>
        {% endblock %}
    {% endembed %}
{% endblock %}
